{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%reload_ext autoreload\n",
    "%autoreload 2\n",
    "\n",
    "import sys\n",
    "sys.path.append(os.path.abspath('../'))\n",
    "from common import *\n",
    "import configs\n",
    "\n",
    "fig_name = 'nested_reparam'\n",
    "fig_dir = join(FIGURE_DIR, fig_name)\n",
    "used_configs = [configs.Warp(), configs.Warp(), configs.Warp(), configs.FiniteDifferences()]\n",
    "technique_names = [\"detach_indirect_si\", \"decouple_reparam\", \"correct\", \"fd\"]\n",
    "technique_names_pretty = [r\"(a) Detached $\\mathbf{x}$\", \"(b) Decoupled \\n reparam.\", \"(c) Correct \\n nesting\", \"(d) Reference \\n (FD)\" ]\n",
    "sensors = [0, 1]\n",
    "y_offset = -0.15\n",
    "fontsize = 12\n",
    "base_size = 3\n",
    "n_rows = len(sensors)\n",
    "n_cols = len(used_configs) + 1\n",
    "total_width = COLUMN_WIDTH\n",
    "fig = plt.figure(1, figsize=(total_width, total_width * 0.475), constrained_layout=False)\n",
    "gs = fig.add_gridspec(n_rows, n_cols, wspace=0.025, hspace=0.025)\n",
    "r_values = [3, 20]\n",
    "for row, (sensor, r_value) in enumerate(zip(sensors, r_values)):\n",
    "    ax = fig.add_subplot(gs[row, 0])\n",
    "    img = read_img(join(fig_dir, f'{sensor}_{technique_names[0]}.exr'), tonemap=True)\n",
    "    img = img[18:-18, 25:-25, :]\n",
    "    aspect = img.shape[0] / img.shape[1]\n",
    "    img = np.repeat(np.repeat(img, 4, axis=0), 4, axis=1)\n",
    "    ax.imshow(img, interpolation='none', extent=[0, 1, 0, aspect])\n",
    "    disable_ticks(ax)\n",
    "    if row == n_rows - 1:\n",
    "        xt = ax.set_title(\"Scene\", fontsize=fontsize, y=y_offset, va='top')\n",
    "    for col, (name, technique_name_pretty) in enumerate(zip(technique_names, technique_names_pretty)):\n",
    "        ax = fig.add_subplot(gs[row, col + 1])\n",
    "        img = read_img(join(fig_dir, f'grad_{sensor}_{name}.exr'), tonemap=False)\n",
    "        img = img[18:-18, 25:-25, :]\n",
    "        aspect = img.shape[0] / img.shape[1]\n",
    "        img = np.repeat(np.repeat(img, 4, axis=0), 4, axis=1)\n",
    "        ax.imshow(np.mean(img, axis=-1), cmap='coolwarm_r', vmin=-r_value, vmax=r_value, interpolation='none', extent=[0, 1, 0, aspect])\n",
    "        disable_ticks(ax)\n",
    "        if row == n_rows - 1:\n",
    "            txt = ax.set_title(technique_name_pretty, fontsize=fontsize, y=y_offset, va='top')\n",
    "plt.margins(0, 0)\n",
    "# save_fig(fig_name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "c8cc192903caa17681aa39d71202092ac11a526d37a1c4ad2948f13605924304"
  },
  "kernelspec": {
   "display_name": "Python 3.10.4 ('mi')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.4"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "c8cc192903caa17681aa39d71202092ac11a526d37a1c4ad2948f13605924304"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
